﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using intelliEssay.Core;
using intelliEssay.Interop;


namespace intelliEssay.Checkers.Font
{

    //添加了endnote。

    //class Program
    //{
    //    static void Main(string[] args)
    //    {
    //    }
    //}
    #region Interop

    public enum TextType
    {
        EnglishLetter,
        ChineseWord,
        Space,
        Punctuation,
        Digit
    }

    public class FontFamily
    {
        public string Font;
        public string AsciiTheme;
        public string Ascii;
        public string EastAsiaTheme;
        public string EastAsia;
        public string HighAnsiTheme;
        public string HighAnsi;
        public string Hint;

        public FontFamily()
        {
            this.Font = this.Ascii = this.AsciiTheme = this.Hint = this.HighAnsiTheme = this.HighAnsi = this.EastAsia = this.EastAsiaTheme = "null";
        }

        public override string ToString()
        {
            return "asciitheme: " + AsciiTheme + " ascii: " + Ascii + " eastasiatheme: " + EastAsiaTheme + " eastasia: " + EastAsia +
                " highansitheme: " + HighAnsiTheme + " highansi: " + HighAnsi + " hint: " + Hint + "  font:  " + Font;
            //return base.ToString();
        }
    }

    public class DefaultProperties
    {
        public bool IsBold;
        public bool IsUnderline;
        public bool IsItalic;
        public string Fontsize;
        public FontFamily FontFamily = new FontFamily();
        public string Color;
        public VerticalTextAlignment VerticalTextAlignment = new VerticalTextAlignment();
        public CharacterScale CharacterScale = new CharacterScale();
        public Spacing Spacing = new Spacing();
        public DefaultProperties()
        {
            IsBold = false;
            IsUnderline = false;
            IsItalic = false;
            Fontsize = "null";
            Color = "auto";
            VerticalTextAlignment.Val = VerticalPositionValues.Baseline;
            CharacterScale.Val = 0;
            Spacing.Val = 0;
        }
    }

    public class RunInfo
    {
        public string Text;
        public StringValue FontSize;
        public StringValue Color;
        public bool IsBold;
        public bool IsUnderline;
        public bool IsItalic;
        public FontFamily FontFamily = new FontFamily();
        public VerticalTextAlignment VerticalTextAlignment = new VerticalTextAlignment();
        public CharacterScale CharacterScale = new CharacterScale();
        public Spacing Spacing = new Spacing();

        public override string ToString()
        {
            //return base.ToString();
            return "******** - New  Run - ********\n[ innertext (" + Text + ") ]\n[ fontsize (" + FontSize + ") ] [ IsBold (" + IsBold.ToString() + ") ] [ IsI (" + IsItalic.ToString() +
                ") ] [ IsU (" + IsUnderline.ToString() + ") ]\n[ color (" + Color + ")]\n" + "[ fontfamily (" + FontFamily.ToString() + ") ]\n[ VerticalTextAlignment ( " +
                VerticalTextAlignment.Val + " )]\n[ CharacterScale (" + CharacterScale.Val + ") ]\n[ Spacing (" + Spacing.Val + ") ]\n******** - Run Over - ********\n";

        }
    }

    public class DocInfo
    {
        public Dictionary<string, Style> DocStyles = new Dictionary<string, Style>();
        public DocDefaults DocDefaultStyle = new DocDefaults();
        public DefaultProperties DefaultProperties = new DefaultProperties();

        public DocInfo() { }
        public DocInfo(Document doc)
        {
            foreach (Style s in doc.MainDocumentPart.StyleDefinitionsPart.Styles.Elements<Style>())
            {
                DocStyles.Add(s.StyleId, s);
            }
            this.DocDefaultStyle = doc.MainDocumentPart.StyleDefinitionsPart.Styles.DocDefaults;

            if (DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.FontSize != null)
                DefaultProperties.Fontsize = DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.FontSize.Val;

            if (DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.RunFonts != null)
            {
                RunFonts runfonts = DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.RunFonts;

                if (runfonts.AsciiTheme != null)
                    DefaultProperties.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
                if (runfonts.Ascii != null)
                    DefaultProperties.FontFamily.Ascii = runfonts.Ascii;
                if (runfonts.EastAsiaTheme != null)
                    DefaultProperties.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
                if (runfonts.EastAsia != null)
                    DefaultProperties.FontFamily.EastAsia = runfonts.EastAsia;
                if (runfonts.HighAnsiTheme != null)
                    DefaultProperties.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
                if (runfonts.HighAnsi != null)
                    DefaultProperties.FontFamily.HighAnsi = runfonts.HighAnsi;
                if (runfonts.Hint != null)
                    DefaultProperties.FontFamily.Hint = runfonts.Hint.ToString();
            }

            if ((DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Bold != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Bold.Val == null) || (DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Bold != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Bold.Val != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Bold.Val.Value != false))
                DefaultProperties.IsBold = true;
            if ((DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Italic != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Italic.Val != null) || (DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Italic != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Italic.Val != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Italic.Val.Value != false))
                DefaultProperties.IsItalic = true;
            if ((DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Underline != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Underline.Val == null) || (DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Underline != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Underline.Val != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Underline.Val != UnderlineValues.None))
                DefaultProperties.IsUnderline = true;
            if (DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Color != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Color.Val != null)
                DefaultProperties.Color = DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Color.Val.Value;
            if (DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.VerticalTextAlignment != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.VerticalTextAlignment.Val != null)
                DefaultProperties.VerticalTextAlignment.Val = DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.VerticalTextAlignment.Val;
            if (DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.CharacterScale != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.CharacterScale.Val != null)
                DefaultProperties.CharacterScale.Val = DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.CharacterScale.Val;
            if (DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Spacing != null && DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Spacing.Val != null)
                DefaultProperties.Spacing.Val = DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.Spacing.Val;




        }
        public DocInfo(List<Style> styles, DocDefaults docDefaultes)
        {
            this.DocDefaultStyle = docDefaultes;
            foreach (Style s in styles)
            {
                DocStyles.Add(s.StyleId, s);
            }
        }

    }

    public class ParagraphInfo
    {
        public string ParagrahStyleId;

        public List<RunInfo> RunInfos = new List<RunInfo>();

        public ParagraphInfo()
        {
            this.ParagrahStyleId = "0";
        }

        public override string ToString()
        {
            //return base.ToString();
            string s = "************ - New Paragraph - *************\n[ ParagraphStyleId ] ( " + ParagrahStyleId + " )\n";
            foreach (RunInfo r in this.RunInfos)
            {
                s += r.ToString() + "\n";
            }
            s += "************* - Paragraph Over - ***********\n\n";
            return s;
        }
    }

    public class FootnoteInfo
    {
        public long Id;
        public List<ParagraphInfo> FootnoteParagraphInfos = new List<ParagraphInfo>();

        public override string ToString()
        {
            //return base.ToString();
            string s = "[ FootnoteId ( " + Id.ToString() + " )]\n";
            foreach (ParagraphInfo pi in FootnoteParagraphInfos)
                s += pi.ToString();
            s += "\n";
            return s;
        }
    }

    public class FootnoteInfos
    {
        public FootnoteInfos(WordprocessingDocument wd)
        {
            List<Footnote> footnotes = new List<Footnote>();
            Helper helper = new Helper(wd.MainDocumentPart.Document);
            footnotes = wd.MainDocumentPart.FootnotesPart.Footnotes.Elements<Footnote>().ToList();
            foreach (Footnote footnote in footnotes)
            {
                if ((long)footnote.Id >= 1)
                {
                    FootnoteInfo footnoteInfo = new FootnoteInfo();
                    footnoteInfo.Id = (long)footnote.Id;
                    foreach (Paragraph paragraph in footnote.Elements<Paragraph>())
                    {
                        footnoteInfo.FootnoteParagraphInfos.Add(helper.GetParagraphInfo(paragraph));
                    }
                    FootnoteInfoList.Add(footnoteInfo);
                }
            }
        }
        public List<FootnoteInfo> FootnoteInfoList = new List<FootnoteInfo>();
        public override string ToString()
        {
            //return base.ToString();
            string s = "";
            foreach (FootnoteInfo fi in FootnoteInfoList)
                s += fi.ToString();
            s += "\n";
            return s;
        }
    }

    public class EndnoteInfo
    {
        public long Id;
        public List<ParagraphInfo> EndnoteParagraphInfos = new List<ParagraphInfo>();
        public override string ToString()
        {
            //return base.ToString();
            string s = "[ EndnoteId ( " + Id.ToString() + " )]\n";
            foreach (ParagraphInfo pi in EndnoteParagraphInfos)
                s += pi.ToString();
            s += "\n";
            return s;
        }
    }

    public class EndnoteInfos
    {
        public EndnoteInfos(WordprocessingDocument wd)
        {
            List<Endnote> endnotes = new List<Endnote>();
            Helper helper = new Helper(wd.MainDocumentPart.Document);
            endnotes = wd.MainDocumentPart.EndnotesPart.Endnotes.Elements<Endnote>().ToList();
            foreach (Endnote endnote in endnotes)
            {
                if ((long)endnote.Id >= 1)
                {
                    EndnoteInfo endnoteInfo = new EndnoteInfo();
                    endnoteInfo.Id = (long)endnote.Id;
                    foreach (Paragraph paragraph in endnote.Elements<Paragraph>())
                    {
                        endnoteInfo.EndnoteParagraphInfos.Add(helper.GetParagraphInfo(paragraph));
                    }
                    EndnoteInfoList.Add(endnoteInfo);
                }
            }
        }
        public List<EndnoteInfo> EndnoteInfoList = new List<EndnoteInfo>();
        public override string ToString()
        {
            //return base.ToString();
            string s = "";
            foreach (EndnoteInfo fi in EndnoteInfoList)
                s += fi.ToString();
            s += "\n";
            return s;
        }
    }

    public class Helper
    {
        public void test() { }

        private static DocInfo DocInfo;

        public Helper(Document doc)
        {
            DocInfo = new DocInfo(doc);
        }

        public Style GetStyle(string styleId)
        {
            return DocInfo.DocStyles[styleId];
        }

        public TextType GetTextType(Run run)
        {
            if (run == null)
            {
                return TextType.Space;
            }
            else
            {
                if (run.InnerText.Trim().Length == 0)
                    return GetTextType(run.PreviousSibling<Run>());
                else
                {
                    char firstOfAll = run.InnerText.Trim().ToLowerInvariant()[0];
                    if (char.IsLower(firstOfAll))
                    {
                        return TextType.EnglishLetter;
                    }
                    else if (char.IsPunctuation(firstOfAll) || char.IsNumber(firstOfAll) || char.IsControl(firstOfAll))
                    {
                        return GetTextType(run.PreviousSibling<Run>());
                    }
                    else
                    {
                        return TextType.ChineseWord;
                    }
                }
            }
        }

        public RunInfo GetRunInfo(Run run)
        {
            Style ParagraphStyle = new Style();
            Paragraph paragraph = new Paragraph();
            bool IsDefault = true;
            if (run.Parent is Paragraph)
            {
                paragraph = run.Parent as Paragraph;
            }
            else if (run.Parent.Parent is Paragraph)
            {
                paragraph = run.Parent.Parent as Paragraph;
            }
            else if (run.Parent.Parent.Parent is Paragraph)
            {
                paragraph = run.Parent.Parent.Parent as Paragraph;
            }
            else
            {
                return null;
            }

            Paragraph preParagraph = paragraph.PreviousSibling<Paragraph>();
            if (preParagraph != null)
            {
                if (preParagraph.ParagraphProperties != null && preParagraph.ParagraphProperties.ParagraphStyleId != null && preParagraph.ParagraphProperties.ParagraphStyleId.Val != null)
                {
                    Style s = DocInfo.DocStyles[preParagraph.ParagraphProperties.ParagraphStyleId.Val];
                    if (s.NextParagraphStyle != null)
                    {
                        ParagraphStyle = DocInfo.DocStyles[s.NextParagraphStyle.Val];
                        IsDefault = false;
                    }
                }
            }

            if (paragraph.ParagraphProperties != null && paragraph.ParagraphProperties.ParagraphStyleId != null && paragraph.ParagraphProperties.ParagraphStyleId.Val != null)
            {
                ParagraphStyle = DocInfo.DocStyles[paragraph.ParagraphProperties.ParagraphStyleId.Val];
                IsDefault = false;
            }


            //get the info of the run
            {
                RunInfo RunInfo = new RunInfo();

                RunInfo.Text = run.InnerText;

                RunInfo.Color = DocInfo.DefaultProperties.Color;
                RunInfo.FontFamily = DocInfo.DefaultProperties.FontFamily;
                RunInfo.FontSize = DocInfo.DefaultProperties.Fontsize;
                RunInfo.IsBold = DocInfo.DefaultProperties.IsBold;
                RunInfo.IsItalic = DocInfo.DefaultProperties.IsItalic;
                RunInfo.IsUnderline = DocInfo.DefaultProperties.IsUnderline;
                RunInfo.VerticalTextAlignment.Val = DocInfo.DefaultProperties.VerticalTextAlignment.Val;
                RunInfo.CharacterScale.Val = DocInfo.DefaultProperties.CharacterScale.Val;
                RunInfo.Spacing.Val = DocInfo.DefaultProperties.Spacing.Val;


                if (!IsDefault)
                {
                    bool hasBasedon = true;
                    Stack<Style> paragraphStyles = new Stack<Style>();
                    while (hasBasedon)
                    {
                        paragraphStyles.Push(ParagraphStyle);
                        if (ParagraphStyle.BasedOn != null && ParagraphStyle.BasedOn.Val != null)
                        {
                            ParagraphStyle = DocInfo.DocStyles[ParagraphStyle.BasedOn.Val];
                        }
                        else
                            hasBasedon = false;
                    }
                    while (paragraphStyles.Count != 0)
                    {
                        ParagraphStyle = paragraphStyles.Pop();
                        if (ParagraphStyle.StyleRunProperties != null)
                        {
                            if (ParagraphStyle.StyleRunProperties.FontSize != null && ParagraphStyle.StyleRunProperties.FontSize.Val != null)
                            {
                                RunInfo.FontSize = ParagraphStyle.StyleRunProperties.FontSize.Val;
                            }
                            if ((ParagraphStyle.StyleRunProperties.Bold != null && ParagraphStyle.StyleRunProperties.Bold.Val == null) || (ParagraphStyle.StyleRunProperties.Bold != null && ParagraphStyle.StyleRunProperties.Bold.Val != null && ParagraphStyle.StyleRunProperties.Bold.Val.Value != false))
                            {
                                RunInfo.IsBold = true;
                            }

                            if ((ParagraphStyle.StyleRunProperties.Italic != null && ParagraphStyle.StyleRunProperties.Italic.Val == null) || (ParagraphStyle.StyleRunProperties.Italic != null && ParagraphStyle.StyleRunProperties.Italic.Val != null && ParagraphStyle.StyleRunProperties.Italic.Val.Value != false))
                            {
                                RunInfo.IsItalic = true;
                            }

                            if ((ParagraphStyle.StyleRunProperties.Underline != null && ParagraphStyle.StyleRunProperties.Underline.Val == null) || (ParagraphStyle.StyleRunProperties.Underline != null && ParagraphStyle.StyleRunProperties.Underline.Val != null && ParagraphStyle.StyleRunProperties.Underline.Val != UnderlineValues.None))
                            {
                                RunInfo.IsUnderline = true;
                            }

                            if (ParagraphStyle.StyleRunProperties.Color != null && ParagraphStyle.StyleRunProperties.Color.Val != null)
                            {
                                RunInfo.Color = ParagraphStyle.StyleRunProperties.Color.Val.Value;
                            }

                            if (ParagraphStyle.StyleRunProperties.VerticalTextAlignment != null && ParagraphStyle.StyleRunProperties.VerticalTextAlignment.Val != null)
                                RunInfo.VerticalTextAlignment.Val = ParagraphStyle.StyleRunProperties.VerticalTextAlignment.Val;
                            if (ParagraphStyle.StyleRunProperties.CharacterScale != null && ParagraphStyle.StyleRunProperties.CharacterScale.Val != null)
                                RunInfo.CharacterScale.Val = ParagraphStyle.StyleRunProperties.CharacterScale.Val;
                            if (ParagraphStyle.StyleRunProperties.Spacing != null && ParagraphStyle.StyleRunProperties.Spacing.Val != null)
                                RunInfo.Spacing.Val = ParagraphStyle.StyleRunProperties.Spacing.Val;

                            /*
                             * 字体
                             */

                            if (ParagraphStyle.StyleRunProperties.RunFonts != null)
                            {
                                RunFonts runfonts = ParagraphStyle.StyleRunProperties.RunFonts;

                                if (runfonts.AsciiTheme != null)
                                    RunInfo.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
                                if (runfonts.Ascii != null)
                                    RunInfo.FontFamily.Ascii = runfonts.Ascii;
                                if (runfonts.EastAsiaTheme != null)
                                    RunInfo.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
                                if (runfonts.EastAsia != null)
                                    RunInfo.FontFamily.EastAsia = runfonts.EastAsia;
                                if (runfonts.HighAnsiTheme != null)
                                    RunInfo.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
                                if (runfonts.HighAnsi != null)
                                    RunInfo.FontFamily.HighAnsi = runfonts.HighAnsi;
                                if (runfonts.Hint != null)
                                    RunInfo.FontFamily.Hint = runfonts.Hint.ToString();
                            }

                        }
                    }
                }

                if (paragraph.ParagraphProperties != null && paragraph.ParagraphProperties.ParagraphMarkRunProperties != null)
                {
                    ParagraphMarkRunProperties pmrp = paragraph.ParagraphProperties.ParagraphMarkRunProperties;
                    if (pmrp.Elements<FontSize>().Count() != 0)
                    {
                        if (pmrp.Elements<FontSize>().First().Val != null)
                            RunInfo.FontSize = pmrp.Elements<FontSize>().First().Val.Value;
                    }
                    if (pmrp.Elements<Bold>().Count() != 0)
                    {
                        Bold bold = pmrp.Elements<Bold>().First();
                        if (bold.Val == null || (bold.Val != null && bold.Val.Value != false))
                            RunInfo.IsBold = true;
                        else
                            RunInfo.IsBold = false;
                    }
                    if (pmrp.Elements<Italic>().Count() != 0)
                    {
                        Italic italic = pmrp.Elements<Italic>().First();
                        if (italic.Val == null || (italic.Val != null && italic.Val.Value != false))
                            RunInfo.IsItalic = true;
                        else
                            RunInfo.IsItalic = false;
                    }
                    if (pmrp.Elements<Underline>().Count() != 0)
                    {
                        Underline underline = pmrp.Elements<Underline>().First();
                        if (underline.Val == null || (underline.Val != null && underline.Val != UnderlineValues.None))
                            RunInfo.IsUnderline = true;
                        else
                            RunInfo.IsUnderline = false;
                    }
                    /*
                     * 字体
                     */
                    if (pmrp.Elements<RunFonts>().Count() != 0)
                    {
                        RunFonts runfonts = pmrp.Elements<RunFonts>().First();

                        if (runfonts.AsciiTheme != null)
                            RunInfo.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
                        if (runfonts.Ascii != null)
                            RunInfo.FontFamily.Ascii = runfonts.Ascii;
                        if (runfonts.EastAsiaTheme != null)
                            RunInfo.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
                        if (runfonts.EastAsia != null)
                            RunInfo.FontFamily.EastAsia = runfonts.EastAsia;
                        if (runfonts.HighAnsiTheme != null)
                            RunInfo.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
                        if (runfonts.HighAnsi != null)
                            RunInfo.FontFamily.HighAnsi = runfonts.HighAnsi;
                        if (runfonts.Hint != null)
                            RunInfo.FontFamily.Hint = runfonts.Hint.ToString();

                    }

                    if (pmrp.Elements<VerticalTextAlignment>().Count() != 0)
                    {
                        if (pmrp.Elements<VerticalTextAlignment>().First().Val != null)
                            RunInfo.VerticalTextAlignment.Val = pmrp.Elements<VerticalTextAlignment>().First().Val;
                    }
                    if (pmrp.Elements<CharacterScale>().Count() != 0)
                    {
                        if (pmrp.Elements<CharacterScale>().First().Val != null)
                            RunInfo.CharacterScale.Val = pmrp.Elements<CharacterScale>().First().Val;
                    }
                    if (pmrp.Elements<Spacing>().Count() != 0)
                    {
                        if (pmrp.Elements<Spacing>().First().Val != null)
                            RunInfo.Spacing.Val = pmrp.Elements<Spacing>().First().Val;
                    }
                }

                if (run.RunProperties != null)
                {
                    if (run.RunProperties.RunStyle != null && run.RunProperties.RunStyle.Val != null)
                    {
                        bool hasBasedOn = true;
                        Stack<Style> runStyles = new Stack<Style>();
                        Style runStyle = DocInfo.DocStyles[run.RunProperties.RunStyle.Val];
                        runStyles.Push(runStyle);
                        while (hasBasedOn)
                        {
                            if (runStyle.BasedOn != null && runStyle.BasedOn.Val != null)
                            {
                                runStyles.Push(DocInfo.DocStyles[runStyle.BasedOn.Val]);
                                runStyle = runStyles.Peek();
                            }
                            else
                                hasBasedOn = false;
                        }

                        while (runStyles.Count != 0)
                        {
                            runStyle = runStyles.Pop();
                            if (runStyle.StyleRunProperties != null)
                            {
                                if (runStyle.StyleRunProperties.FontSize != null && runStyle.StyleRunProperties.FontSize.Val != null)
                                {
                                    RunInfo.FontSize = runStyle.StyleRunProperties.FontSize.Val;
                                }
                                if ((runStyle.StyleRunProperties.Bold != null && runStyle.StyleRunProperties.Bold.Val == null) || (runStyle.StyleRunProperties.Bold != null && runStyle.StyleRunProperties.Bold.Val != null && runStyle.StyleRunProperties.Bold.Val.Value != false))
                                {
                                    RunInfo.IsBold = true;
                                }

                                if ((runStyle.StyleRunProperties.Italic != null && runStyle.StyleRunProperties.Italic.Val == null) || (runStyle.StyleRunProperties.Italic != null && runStyle.StyleRunProperties.Italic.Val != null && runStyle.StyleRunProperties.Italic.Val.Value != false))
                                {
                                    RunInfo.IsItalic = true;
                                }

                                if ((runStyle.StyleRunProperties.Underline != null && runStyle.StyleRunProperties.Underline.Val == null) || (runStyle.StyleRunProperties.Underline != null && runStyle.StyleRunProperties.Underline.Val != null && runStyle.StyleRunProperties.Underline.Val != UnderlineValues.None))
                                {
                                    RunInfo.IsUnderline = true;
                                }

                                if (runStyle.StyleRunProperties.Color != null && runStyle.StyleRunProperties.Color.Val != null)
                                {
                                    RunInfo.Color = runStyle.StyleRunProperties.Color.Val.Value;
                                }

                                if (runStyle.StyleRunProperties.VerticalTextAlignment != null && runStyle.StyleRunProperties.VerticalTextAlignment.Val != null)
                                    RunInfo.VerticalTextAlignment.Val = runStyle.StyleRunProperties.VerticalTextAlignment.Val;
                                if (runStyle.StyleRunProperties.CharacterScale != null && runStyle.StyleRunProperties.CharacterScale.Val != null)
                                    RunInfo.CharacterScale.Val = runStyle.StyleRunProperties.CharacterScale.Val;
                                if (runStyle.StyleRunProperties.Spacing != null && runStyle.StyleRunProperties.Spacing.Val != null)
                                    RunInfo.Spacing.Val = runStyle.StyleRunProperties.Spacing.Val;

                                //

                                if (runStyle.StyleRunProperties.RunFonts != null)
                                {
                                    RunFonts runfonts = runStyle.StyleRunProperties.RunFonts;

                                    if (runfonts.AsciiTheme != null)
                                        RunInfo.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
                                    if (runfonts.Ascii != null)
                                        RunInfo.FontFamily.Ascii = runfonts.Ascii;
                                    if (runfonts.EastAsiaTheme != null)
                                        RunInfo.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
                                    if (runfonts.EastAsia != null)
                                        RunInfo.FontFamily.EastAsia = runfonts.EastAsia;
                                    if (runfonts.HighAnsiTheme != null)
                                        RunInfo.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
                                    if (runfonts.HighAnsi != null)
                                        RunInfo.FontFamily.HighAnsi = runfonts.HighAnsi;
                                    if (runfonts.Hint != null)
                                        RunInfo.FontFamily.Hint = runfonts.Hint.ToString();
                                }

                            }

                        }

                    }

                    if (run.RunProperties.Bold != null)
                    {
                        if ((run.RunProperties.Bold.Val == null) || (run.RunProperties.Bold != null && run.RunProperties.Bold.Val != null && run.RunProperties.Bold.Val != false))
                            RunInfo.IsBold = true;
                        else
                            RunInfo.IsBold = false;
                    }

                    if (run.RunProperties.Italic != null)
                    {
                        if ((run.RunProperties.Italic.Val == null) || (run.RunProperties.Italic != null && run.RunProperties.Italic.Val != null && run.RunProperties.Italic.Val != false))
                            RunInfo.IsItalic = true;
                        else
                            RunInfo.IsItalic = false;
                    }

                    if (run.RunProperties.Underline != null)
                    {
                        if ((run.RunProperties.Underline.Val == null) || (run.RunProperties.Underline != null && run.RunProperties.Underline.Val != null && run.RunProperties.Underline.Val != UnderlineValues.None))
                            RunInfo.IsUnderline = true;
                        else
                            RunInfo.IsUnderline = false;
                    }

                    if (run.RunProperties.FontSize != null && run.RunProperties.FontSize.Val != null)
                    {
                        RunInfo.FontSize = run.RunProperties.FontSize.Val;
                    }
                    if (run.RunProperties.Color != null && run.RunProperties.Color.Val != null)
                    {
                        RunInfo.Color = run.RunProperties.Color.Val;
                    }

                    /*
                     * 字体
                     */

                    if (run.RunProperties.RunFonts != null)
                    {
                        RunFonts runfonts = run.RunProperties.RunFonts;

                        if (runfonts.AsciiTheme != null)
                            RunInfo.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
                        if (runfonts.Ascii != null)
                            RunInfo.FontFamily.Ascii = runfonts.Ascii;
                        if (runfonts.EastAsiaTheme != null)
                            RunInfo.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
                        if (runfonts.EastAsia != null)
                            RunInfo.FontFamily.EastAsia = runfonts.EastAsia;
                        if (runfonts.HighAnsiTheme != null)
                            RunInfo.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
                        if (runfonts.HighAnsi != null)
                            RunInfo.FontFamily.HighAnsi = runfonts.HighAnsi;
                        if (runfonts.Hint != null)
                            RunInfo.FontFamily.Hint = runfonts.Hint.ToString();
                    }

                    if (run.RunProperties.VerticalTextAlignment != null && run.RunProperties.VerticalTextAlignment.Val != null)
                        RunInfo.VerticalTextAlignment.Val = run.RunProperties.VerticalTextAlignment.Val;
                    if (run.RunProperties.CharacterScale != null && run.RunProperties.CharacterScale.Val != null)
                        RunInfo.CharacterScale.Val = run.RunProperties.CharacterScale.Val;
                    if (run.RunProperties.Spacing != null && run.RunProperties.Spacing.Val != null)
                        RunInfo.Spacing.Val = run.RunProperties.Spacing.Val;
                }
                /*
                 * 字体
                 */
                #region 判断字体
                if (GetTextType(run) == TextType.EnglishLetter)
                {
                    RunInfo.FontFamily.Font = "Calibri";
                    if (RunInfo.FontFamily.Hint == "eastAsia")
                        RunInfo.FontFamily.Font = "宋体";
                    else
                        RunInfo.FontFamily.Font = "Calibri";

                    if (RunInfo.FontFamily.Ascii != "null")
                        RunInfo.FontFamily.Font = RunInfo.FontFamily.Ascii;
                    if (RunInfo.FontFamily.AsciiTheme == "majorHAnsi")
                        RunInfo.FontFamily.Font = "Cambria";
                    else if (RunInfo.FontFamily.AsciiTheme == "minorHAnsi")
                        RunInfo.FontFamily.Font = "Calibri";
                    else if (RunInfo.FontFamily.AsciiTheme == "minorEastAsia" || RunInfo.FontFamily.AsciiTheme == "majorEastAsia")
                        RunInfo.FontFamily.Font = "宋体";

                    if (RunInfo.FontFamily.HighAnsi != "null")
                        RunInfo.FontFamily.Font = RunInfo.FontFamily.HighAnsi;
                    if (RunInfo.FontFamily.HighAnsiTheme == "majorHAnsi")
                        RunInfo.FontFamily.Font = "Cambria";
                    else if (RunInfo.FontFamily.HighAnsiTheme == "minorHAnsi")
                        RunInfo.FontFamily.Font = "Calibri";
                }
                else if (GetTextType(run) == TextType.ChineseWord)
                {
                    RunInfo.FontFamily.Font = "宋体";
                    if (RunInfo.FontFamily.AsciiTheme == "minorEastAsia" || RunInfo.FontFamily.AsciiTheme == "majorEastAsia")
                        RunInfo.FontFamily.Font = "宋体";
                    else if (RunInfo.FontFamily.Ascii != "null")
                    {
                        RunInfo.FontFamily.Font = RunInfo.FontFamily.Ascii;
                    }
                    if (RunInfo.FontFamily.EastAsiaTheme == "minorEastAsia" || RunInfo.FontFamily.EastAsiaTheme == "majorEastAsia")
                        RunInfo.FontFamily.Font = "宋体";
                    if (RunInfo.FontFamily.Hint == "eastAsia")
                        RunInfo.FontFamily.Font = "宋体";
                    if (RunInfo.FontFamily.EastAsia != "null")
                        RunInfo.FontFamily.Font = RunInfo.FontFamily.EastAsia;

                }
                else
                {
                    RunInfo.FontFamily.Font = "宋体";
                }
                #endregion
                return RunInfo;
            }

            //foreach
        }

        public ParagraphInfo GetParagraphInfo(Paragraph paragraph)
        {

            ParagraphInfo paragraphInfo = new ParagraphInfo();
            Style ParagraphStyle = new Style();
            bool IsDefault = true;

            List<RunInfo> RunInfos = new List<RunInfo>();

            Paragraph preParagraph = paragraph.PreviousSibling<Paragraph>();
            if (preParagraph != null)
            {
                if (preParagraph.ParagraphProperties != null && preParagraph.ParagraphProperties.ParagraphStyleId != null && preParagraph.ParagraphProperties.ParagraphStyleId.Val != null)
                {
                    Style s = DocInfo.DocStyles[preParagraph.ParagraphProperties.ParagraphStyleId.Val];
                    if (s.NextParagraphStyle != null)
                    {
                        ParagraphStyle = DocInfo.DocStyles[s.NextParagraphStyle.Val];
                        paragraphInfo.ParagrahStyleId = ParagraphStyle.StyleId; //paragraph.ParagraphProperties.ParagraphStyleId.Val;
                        IsDefault = false;
                    }
                }
            }

            if (paragraph.ParagraphProperties != null && paragraph.ParagraphProperties.ParagraphStyleId != null && paragraph.ParagraphProperties.ParagraphStyleId.Val != null)
            {
                ParagraphStyle = DocInfo.DocStyles[paragraph.ParagraphProperties.ParagraphStyleId.Val];
                paragraphInfo.ParagrahStyleId = paragraph.ParagraphProperties.ParagraphStyleId.Val;
                IsDefault = false;
            }



            foreach (Run run in paragraph.Elements<Run>())
            {
                paragraphInfo.RunInfos.Add(GetRunInfo(run));
            }
            return paragraphInfo;
        }



        //public  ParagraphInfo GetParagraphInfo(Paragraph paragraph)
        //{

        //    ParagraphInfo paragraphInfo = new ParagraphInfo();
        //    Style ParagraphStyle = new Style();
        //    bool IsDefault = true;

        //    List<RunInfo> RunInfos = new List<RunInfo>();

        //    Paragraph preParagraph = paragraph.PreviousSibling<Paragraph>();
        //    if (preParagraph != null)
        //    {
        //        if (preParagraph.ParagraphProperties != null && preParagraph.ParagraphProperties.ParagraphStyleId != null && preParagraph.ParagraphProperties.ParagraphStyleId.Val != null)
        //        {
        //            Style s = DocInfo.DocStyles[preParagraph.ParagraphProperties.ParagraphStyleId.Val];
        //            if (s.NextParagraphStyle != null)
        //            {
        //                ParagraphStyle = DocInfo.DocStyles[s.NextParagraphStyle.Val];
        //                paragraphInfo.ParagrahStyleId = ParagraphStyle.StyleId; //paragraph.ParagraphProperties.ParagraphStyleId.Val;
        //                IsDefault = false;
        //            }
        //        }
        //    }

        //    if (paragraph.ParagraphProperties != null && paragraph.ParagraphProperties.ParagraphStyleId != null && paragraph.ParagraphProperties.ParagraphStyleId.Val != null)
        //    {
        //        ParagraphStyle = DocInfo.DocStyles[paragraph.ParagraphProperties.ParagraphStyleId.Val];
        //        paragraphInfo.ParagrahStyleId = paragraph.ParagraphProperties.ParagraphStyleId.Val;
        //        IsDefault = false;
        //    }



        //    foreach (Run run in paragraph.Elements<Run>())
        //    {
        //        RunInfo RunInfo = new RunInfo();

        //        RunInfo.Text = run.InnerText;

        //        RunInfo.Color = DocInfo.DefaultProperties.Color;
        //        RunInfo.FontFamily = DocInfo.DefaultProperties.FontFamily;
        //        RunInfo.FontSize = DocInfo.DefaultProperties.Fontsize;
        //        RunInfo.IsBold = DocInfo.DefaultProperties.IsBold;
        //        RunInfo.IsItalic = DocInfo.DefaultProperties.IsItalic;
        //        RunInfo.IsUnderline = DocInfo.DefaultProperties.IsUnderline;
        //        RunInfo.VerticalTextAlignment.Val = DocInfo.DefaultProperties.VerticalTextAlignment.Val;
        //        RunInfo.CharacterScale.Val = DocInfo.DefaultProperties.CharacterScale.Val;
        //        RunInfo.Spacing.Val = DocInfo.DefaultProperties.Spacing.Val;

        //        #region initialize the default properties

        //        //if (DocInfo.DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.FontSize != null)
        //        //    RunInfo.FontSize = DocInfo.DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.FontSize.Val.Value;
        //        //RunInfo.IsBold = false;
        //        //RunInfo.IsItalic = false;
        //        //RunInfo.IsUnderline = false;
        //        //RunInfo.Color = "auto";
        //        //RunInfo.Text = run.InnerText;
        //        ////FontFamily
        //        //{
        //        //    if (DocInfo.DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.RunFonts != null)
        //        //    {
        //        //        RunFonts runfonts = DocInfo.DocDefaultStyle.RunPropertiesDefault.RunPropertiesBaseStyle.RunFonts;

        //        //        if (runfonts.AsciiTheme != null)
        //        //            RunInfo.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
        //        //        if (runfonts.Ascii != null)
        //        //            RunInfo.FontFamily.Ascii = runfonts.Ascii;
        //        //        if (runfonts.EastAsiaTheme != null)
        //        //            RunInfo.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
        //        //        if (runfonts.EastAsia != null)
        //        //            RunInfo.FontFamily.EastAsia = runfonts.EastAsia;
        //        //        if (runfonts.HighAnsiTheme != null)
        //        //            RunInfo.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
        //        //        if (runfonts.HighAnsi != null)
        //        //            RunInfo.FontFamily.HighAnsi = runfonts.HighAnsi;
        //        //        if (runfonts.Hint != null)
        //        //            RunInfo.FontFamily.Hint = runfonts.Hint.ToString();
        //        //    }
        //        //}

        //        #endregion

        //        if (!IsDefault)
        //        {
        //            bool hasBasedon = true;
        //            Stack<Style> paragraphStyles = new Stack<Style>();
        //            while (hasBasedon)
        //            {
        //                paragraphStyles.Push(ParagraphStyle);
        //                if (ParagraphStyle.BasedOn != null && ParagraphStyle.BasedOn.Val != null)
        //                {
        //                    ParagraphStyle = DocInfo.DocStyles[ParagraphStyle.BasedOn.Val];
        //                }
        //                else
        //                    hasBasedon = false;
        //            }
        //            while (paragraphStyles.Count != 0)
        //            {
        //                ParagraphStyle = paragraphStyles.Pop();
        //                if (ParagraphStyle.StyleRunProperties != null)
        //                {
        //                    if (ParagraphStyle.StyleRunProperties.FontSize != null && ParagraphStyle.StyleRunProperties.FontSize.Val != null)
        //                    {
        //                        RunInfo.FontSize = ParagraphStyle.StyleRunProperties.FontSize.Val;
        //                    }
        //                    if ((ParagraphStyle.StyleRunProperties.Bold != null && ParagraphStyle.StyleRunProperties.Bold.Val == null) || (ParagraphStyle.StyleRunProperties.Bold != null && ParagraphStyle.StyleRunProperties.Bold.Val != null && ParagraphStyle.StyleRunProperties.Bold.Val.Value != false))
        //                    {
        //                        RunInfo.IsBold = true;
        //                    }

        //                    if ((ParagraphStyle.StyleRunProperties.Italic != null && ParagraphStyle.StyleRunProperties.Italic.Val != null) || (ParagraphStyle.StyleRunProperties.Italic != null && ParagraphStyle.StyleRunProperties.Italic.Val != null && ParagraphStyle.StyleRunProperties.Italic.Val.Value != false))
        //                    {
        //                        RunInfo.IsItalic = true;
        //                    }

        //                    if (ParagraphStyle.StyleRunProperties.Underline != null)
        //                    {
        //                        RunInfo.IsUnderline = true;
        //                    }

        //                    if (ParagraphStyle.StyleRunProperties.Color != null && ParagraphStyle.StyleRunProperties.Color.Val != null)
        //                    {
        //                        RunInfo.Color = ParagraphStyle.StyleRunProperties.Color.Val.Value;
        //                    }

        //                    if (ParagraphStyle.StyleRunProperties.VerticalTextAlignment != null && ParagraphStyle.StyleRunProperties.VerticalTextAlignment.Val != null)
        //                        RunInfo.VerticalTextAlignment.Val = ParagraphStyle.StyleRunProperties.VerticalTextAlignment.Val;
        //                    if (ParagraphStyle.StyleRunProperties.CharacterScale != null && ParagraphStyle.StyleRunProperties.CharacterScale.Val != null)
        //                        RunInfo.CharacterScale.Val = ParagraphStyle.StyleRunProperties.CharacterScale.Val;
        //                    if (ParagraphStyle.StyleRunProperties.Spacing != null && ParagraphStyle.StyleRunProperties.Spacing.Val != null)
        //                        RunInfo.Spacing.Val = ParagraphStyle.StyleRunProperties.Spacing.Val;

        //                    //

        //                    if (ParagraphStyle.StyleRunProperties.RunFonts != null)
        //                    {
        //                        RunFonts runfonts = ParagraphStyle.StyleRunProperties.RunFonts;

        //                        if (runfonts.AsciiTheme != null)
        //                            RunInfo.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
        //                        if (runfonts.Ascii != null)
        //                            RunInfo.FontFamily.Ascii = runfonts.Ascii;
        //                        if (runfonts.EastAsiaTheme != null)
        //                            RunInfo.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
        //                        if (runfonts.EastAsia != null)
        //                            RunInfo.FontFamily.EastAsia = runfonts.EastAsia;
        //                        if (runfonts.HighAnsiTheme != null)
        //                            RunInfo.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
        //                        if (runfonts.HighAnsi != null)
        //                            RunInfo.FontFamily.HighAnsi = runfonts.HighAnsi;
        //                        if (runfonts.Hint != null)
        //                            RunInfo.FontFamily.Hint = runfonts.Hint.ToString();
        //                    }

        //                }
        //            }
        //        }

        //        if (paragraph.ParagraphProperties != null && paragraph.ParagraphProperties.ParagraphMarkRunProperties != null)
        //        {
        //            ParagraphMarkRunProperties pmrp = paragraph.ParagraphProperties.ParagraphMarkRunProperties;
        //            if (pmrp.Elements<FontSize>().Count() != 0)
        //            {
        //                if (pmrp.Elements<FontSize>().First().Val != null)
        //                    RunInfo.FontSize = pmrp.Elements<FontSize>().First().Val.Value;
        //            }
        //            if (pmrp.Elements<Bold>().Count() != 0)
        //            {
        //                Bold bold = pmrp.Elements<Bold>().First();
        //                if (bold.Val == null || (bold.Val != null && bold.Val != null && bold.Val.Value != false))
        //                    RunInfo.IsBold = true;
        //                else
        //                    RunInfo.IsBold = false;
        //            }
        //            if (pmrp.Elements<Italic>().Count() != 0)
        //            {
        //                Italic italic = pmrp.Elements<Italic>().First();
        //                if (italic.Val == null || (italic.Val != null && italic.Val != null && italic.Val.Value != false))
        //                    RunInfo.IsItalic = true;
        //                else
        //                    RunInfo.IsItalic = false;
        //            }
        //            if (pmrp.Elements<RunFonts>().Count() != 0)
        //            {
        //                RunFonts runfonts = pmrp.Elements<RunFonts>().First();
        //                if (runfonts.AsciiTheme != null)
        //                    RunInfo.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
        //                if (runfonts.Ascii != null)
        //                    RunInfo.FontFamily.Ascii = runfonts.Ascii;
        //                if (runfonts.EastAsiaTheme != null)
        //                    RunInfo.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
        //                if (runfonts.EastAsia != null)
        //                    RunInfo.FontFamily.EastAsia = runfonts.EastAsia;
        //                if (runfonts.HighAnsiTheme != null)
        //                    RunInfo.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
        //                if (runfonts.HighAnsi != null)
        //                    RunInfo.FontFamily.HighAnsi = runfonts.HighAnsi;
        //                if (runfonts.Hint != null)
        //                    RunInfo.FontFamily.Hint = runfonts.Hint.ToString();

        //            }

        //            if (pmrp.Elements<VerticalTextAlignment>().Count() != 0)
        //            {
        //                if (pmrp.Elements<VerticalTextAlignment>().First().Val != null)
        //                    RunInfo.VerticalTextAlignment.Val = pmrp.Elements<VerticalTextAlignment>().First().Val;
        //            }
        //            if (pmrp.Elements<CharacterScale>().Count() != 0)
        //            {
        //                if (pmrp.Elements<CharacterScale>().First().Val != null)
        //                    RunInfo.CharacterScale.Val = pmrp.Elements<CharacterScale>().First().Val;
        //            }
        //            if (pmrp.Elements<Spacing>().Count() != 0)
        //            {
        //                if (pmrp.Elements<Spacing>().First().Val != null)
        //                    RunInfo.Spacing.Val = pmrp.Elements<Spacing>().First().Val;
        //            }
        //        }


        //        if (run.RunProperties != null)
        //        {
        //            if (run.RunProperties.RunStyle != null && run.RunProperties.RunStyle.Val != null)
        //            {
        //                bool hasBasedOn=true;
        //                Stack<Style> runStyles = new Stack<Style>();
        //                Style runStyle = DocInfo.DocStyles[run.RunProperties.RunStyle.Val];
        //                while (hasBasedOn)
        //                {
        //                    runStyles.Push(ParagraphStyle);
        //                    if (runStyle.BasedOn != null && runStyle.BasedOn.Val != null)
        //                    {
        //                        runStyles.Push(DocInfo.DocStyles[runStyle.BasedOn.Val]);
        //                        runStyle = runStyles.Peek();
        //                    }
        //                    else
        //                        hasBasedOn = false;
        //                }

        //                while (runStyles.Count != 0)
        //                {
        //                    runStyle = runStyles.Pop();
        //                    if (runStyle.StyleRunProperties != null)
        //                    {
        //                        if (runStyle.StyleRunProperties.FontSize != null && runStyle.StyleRunProperties.FontSize.Val != null)
        //                        {
        //                            RunInfo.FontSize = runStyle.StyleRunProperties.FontSize.Val;
        //                        }
        //                        if ((runStyle.StyleRunProperties.Bold != null && runStyle.StyleRunProperties.Bold.Val == null) || (runStyle.StyleRunProperties.Bold != null && runStyle.StyleRunProperties.Bold.Val != null && runStyle.StyleRunProperties.Bold.Val.Value != false))
        //                        {
        //                            RunInfo.IsBold = true;
        //                        }

        //                        if ((runStyle.StyleRunProperties.Italic != null && runStyle.StyleRunProperties.Italic.Val != null) || (runStyle.StyleRunProperties.Italic != null && runStyle.StyleRunProperties.Italic.Val != null && runStyle.StyleRunProperties.Italic.Val.Value != false))
        //                        {
        //                            RunInfo.IsItalic = true;
        //                        }

        //                        if (runStyle.StyleRunProperties.Underline != null)
        //                        {
        //                            RunInfo.IsUnderline = true;
        //                        }

        //                        if (runStyle.StyleRunProperties.Color != null && runStyle.StyleRunProperties.Color.Val != null)
        //                        {
        //                            RunInfo.Color = runStyle.StyleRunProperties.Color.Val.Value;
        //                        }

        //                        if (runStyle.StyleRunProperties.VerticalTextAlignment != null && runStyle.StyleRunProperties.VerticalTextAlignment.Val != null)
        //                            RunInfo.VerticalTextAlignment.Val = runStyle.StyleRunProperties.VerticalTextAlignment.Val;
        //                        if (runStyle.StyleRunProperties.CharacterScale != null && runStyle.StyleRunProperties.CharacterScale.Val != null)
        //                            RunInfo.CharacterScale.Val = runStyle.StyleRunProperties.CharacterScale.Val;
        //                        if (runStyle.StyleRunProperties.Spacing != null && runStyle.StyleRunProperties.Spacing.Val != null)
        //                            RunInfo.Spacing.Val = runStyle.StyleRunProperties.Spacing.Val;

        //                        //

        //                        if (runStyle.StyleRunProperties.RunFonts != null)
        //                        {
        //                            RunFonts runfonts = runStyle.StyleRunProperties.RunFonts;

        //                            if (runfonts.AsciiTheme != null)
        //                                RunInfo.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
        //                            if (runfonts.Ascii != null)
        //                                RunInfo.FontFamily.Ascii = runfonts.Ascii;
        //                            if (runfonts.EastAsiaTheme != null)
        //                                RunInfo.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
        //                            if (runfonts.EastAsia != null)
        //                                RunInfo.FontFamily.EastAsia = runfonts.EastAsia;
        //                            if (runfonts.HighAnsiTheme != null)
        //                                RunInfo.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
        //                            if (runfonts.HighAnsi != null)
        //                                RunInfo.FontFamily.HighAnsi = runfonts.HighAnsi;
        //                            if (runfonts.Hint != null)
        //                                RunInfo.FontFamily.Hint = runfonts.Hint.ToString();
        //                        }

        //                    }

        //                }

        //            }

        //            if (run.RunProperties.Bold != null)
        //            {
        //                if ((run.RunProperties.Bold.Val == null) || (run.RunProperties.Bold != null && run.RunProperties.Bold.Val != null && run.RunProperties.Bold.Val != false))
        //                    RunInfo.IsBold = true;
        //                else
        //                    RunInfo.IsBold = false;
        //            }

        //            if (run.RunProperties.Italic != null)
        //            {
        //                if ((run.RunProperties.Italic.Val == null) || (run.RunProperties.Italic != null && run.RunProperties.Italic.Val != null && run.RunProperties.Italic.Val != false))
        //                    RunInfo.IsItalic = true;
        //                else
        //                    RunInfo.IsItalic = false;
        //            }

        //            if (run.RunProperties.Underline != null)
        //            {
        //                RunInfo.IsUnderline = true;
        //            }

        //            if (run.RunProperties.FontSize != null && run.RunProperties.FontSize.Val != null)
        //            {
        //                RunInfo.FontSize = run.RunProperties.FontSize.Val;
        //            }
        //            if (run.RunProperties.Color != null && run.RunProperties.Color.Val != null)
        //            {
        //                RunInfo.Color = run.RunProperties.Color.Val;
        //            }

        //            //
        //            {
        //                if (run.RunProperties.RunFonts != null)
        //                {
        //                    RunFonts runfonts = run.RunProperties.RunFonts;

        //                    if (runfonts.AsciiTheme != null)
        //                        RunInfo.FontFamily.AsciiTheme = runfonts.AsciiTheme.ToString();
        //                    if (runfonts.Ascii != null)
        //                        RunInfo.FontFamily.Ascii = runfonts.Ascii;
        //                    if (runfonts.EastAsiaTheme != null)
        //                        RunInfo.FontFamily.EastAsiaTheme = runfonts.EastAsiaTheme.ToString();
        //                    if (runfonts.EastAsia != null)
        //                        RunInfo.FontFamily.EastAsia = runfonts.EastAsia;
        //                    if (runfonts.HighAnsiTheme != null)
        //                        RunInfo.FontFamily.HighAnsiTheme = runfonts.HighAnsiTheme.ToString();
        //                    if (runfonts.HighAnsi != null)
        //                        RunInfo.FontFamily.HighAnsi = runfonts.HighAnsi;
        //                    if (runfonts.Hint != null)
        //                        RunInfo.FontFamily.Hint = runfonts.Hint.ToString();
        //                }
        //            }
        //            if (run.RunProperties.VerticalTextAlignment != null && run.RunProperties.VerticalTextAlignment.Val != null)
        //                RunInfo.VerticalTextAlignment.Val = run.RunProperties.VerticalTextAlignment.Val;
        //            if (run.RunProperties.CharacterScale != null && run.RunProperties.CharacterScale.Val != null)
        //                RunInfo.CharacterScale.Val = run.RunProperties.CharacterScale.Val;
        //            if (run.RunProperties.Spacing != null && run.RunProperties.Spacing.Val != null)
        //                RunInfo.Spacing.Val = run.RunProperties.Spacing.Val;



        //        }
        //        //font
        //        {
        //            #region 判断字体
        //            if (GetTextType(run) == TextType.EnglishLetter)
        //            {
        //                RunInfo.FontFamily.Font = "Calibri";
        //                if (RunInfo.FontFamily.Hint == "eastAsia")
        //                    RunInfo.FontFamily.Font = "宋体";
        //                else
        //                    RunInfo.FontFamily.Font = "Calibri";

        //                if (RunInfo.FontFamily.Ascii != "null")
        //                    RunInfo.FontFamily.Font = RunInfo.FontFamily.Ascii;
        //                if (RunInfo.FontFamily.AsciiTheme == "majorHAnsi")
        //                    RunInfo.FontFamily.Font = "Cambria";
        //                else if (RunInfo.FontFamily.AsciiTheme == "minorHAnsi")
        //                    RunInfo.FontFamily.Font = "Calibri";
        //                else if (RunInfo.FontFamily.AsciiTheme == "minorEastAsia" || RunInfo.FontFamily.AsciiTheme == "majorEastAsia")
        //                    RunInfo.FontFamily.Font = "宋体";

        //                if (RunInfo.FontFamily.HighAnsi != "null")
        //                    RunInfo.FontFamily.Font = RunInfo.FontFamily.HighAnsi;
        //                if (RunInfo.FontFamily.HighAnsiTheme == "majorHAnsi")
        //                    RunInfo.FontFamily.Font = "Cambria";
        //                else if (RunInfo.FontFamily.HighAnsiTheme == "minorHAnsi")
        //                    RunInfo.FontFamily.Font = "Calibri";
        //            }
        //            else if (GetTextType(run) == TextType.ChineseWord)
        //            {
        //                RunInfo.FontFamily.Font = "宋体";
        //                if (RunInfo.FontFamily.AsciiTheme == "minorEastAsia" || RunInfo.FontFamily.AsciiTheme == "majorEastAsia")
        //                    RunInfo.FontFamily.Font = "宋体";
        //                else if (RunInfo.FontFamily.Ascii != "null")
        //                {
        //                    RunInfo.FontFamily.Font = RunInfo.FontFamily.Ascii;
        //                }
        //                if (RunInfo.FontFamily.EastAsiaTheme == "minorEastAsia" || RunInfo.FontFamily.EastAsiaTheme == "majorEastAsia")
        //                    RunInfo.FontFamily.Font = "宋体";
        //                if (RunInfo.FontFamily.EastAsia != "null")
        //                    RunInfo.FontFamily.Font = RunInfo.FontFamily.EastAsia;
        //                if (RunInfo.FontFamily.Hint == "eastAsia")
        //                    RunInfo.FontFamily.Font = "宋体";

        //            }
        //            else
        //            {
        //                RunInfo.FontFamily.Font = "宋体";
        //            }
        //            #endregion
        //        }
        //        RunInfos.Add(RunInfo);
        //    }
        //    paragraphInfo.RunInfos = RunInfos;
        //    return paragraphInfo;
        //}

    }

    #endregion

    namespace StandardFormat
    {
        struct Format
        {

        }

        class StandardFormats
        {

        }
    }
}
